package com.hackintosh.singleton.pattern.hungry;

import javax.swing.*;
import java.awt.*;

/**
 * @description：用饿汉式单例模式模拟产生猪八戒对象
 * @author：twislyn
 * @date：Created in 2021/05/04
 * @modified By：
 * @version: 1.0
 */
public class SingletonEager {
    public static void main(String[] args) {
        JFrame jFrame = new JFrame("饿汉单例模式");
        jFrame.setLayout(new GridLayout(1,2));
        Container container = jFrame.getContentPane();
        Bajie obj1 = Bajie.getInstance();
        container.add(obj1);
        Bajie obj2 = Bajie.getInstance();
        container.add(obj2);

        if(obj1==obj2){
            System.out.println("他们是同一个人");
        }else {
            System.out.println("他们不是同一个人");
        }
        jFrame.pack();
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
